home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
The World of Computer Software.iso
/
face2ps.zip
/
FACE2PS.C
next >
Wrap
C/C++ Source or Header
|
1993-01-25
|
7KB
|
203 lines
Here is a slightly updated version of the "printuface.c" program
provided by faceserver's "send format" request. It is called
"face2ps.c", solely because I don't like the name "printuface" (well... and
because it doesn't PRINT anything, it only converts). This one doesn't
care where interesting header lines are, as long as they start with the
right keywords (case sensitive!!). It is by no means bulletproof, but
it should do a better job than the current program.
Please distribute freely. Thanks for the faceserver.
-David
----------------------------------------------------------------------------
/* Simple program to read in an 8-bit deep picture file from a Targa M8
* board and display it via PostScript.
*
* Copyright 1988,1989 Metron Computerware, Ltd. Oakland, CA 94602
* Unpublished work of Metron Computerware, Ltd. All rights reserved.
*
* Small pictures have already been rotated from the original raster by the
* capture program to print in a proper orientation on the paper.
*
* Last revised 21 March 1989
*
* This program first outputs a postscript program to stdout.
* It then reads stdin or a file to get the hexified image.
* It sends this postscript stuff to stdout.
*
* Usage: face2ps [fn] [< hexpicturefile] > postscriptdevice
* if any argument is supplied at all, the program expects to read
* that as a uunet formatted file. Otherwise it reads that format
* from stdin.
*
* cc -o face2ps face2ps.c
*
* The pixels on a Targa board are not quite square. In fact, they are
* off by the ratio 96:108, very nearly
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Now supports non-fixed uunet faceserver header format. The order and
* number of lines in the header don't matter, but keywords are still case
* sensitive. Header is terminated by a blank line.
*
* Updated 21 December 1990
*
* Copyright (c) 1990, David Reisner Consulting. All rights reserved.
* Please distribute freely, but don't remove the copyright notices.
* Internet: synthesis!dar@ucsd.edu; Faceserver: synthesis.uucp/dar.
*
*/
#include <stdio.h>
#include <string.h>
#define SERIAL
char scanline[256]; /* Input for one scanline */
main(argc,argv)
int argc;
char **argv;
{
int d,i,j,k,l,m;
char textout[256];
char header[128]; /* A line from the header, which may be..*/
char fname[128]; /* The first name behind the face */
char lname[128]; /* The last name behind the face */
char netaddr[128]; /* Net address, if any */
char pixinfo[128]; /* width, height, depth of data */
char imageinfo[128]; /* width, height, depth of image */
unsigned char ch,*cp;
FILE *fp;
int pt = 18; /* pointsize for message */
k = 128; /* Normal image */
l = 108;
if (argc > 1) {
fp = fopen(argv[1],"r");
if (fp == NULL) {
printf("Can't open %s for input\n",argv[1]);
exit (1);
}
}
else
fp = stdin;
/* Extract the "FirstName:", "LastName:", "E-Mail:", "PicData:", and
"Image:" info from the header (terminated by a blank line). */
while (strlen(fgets(header, 127,fp)) > 1)
{
if (strstr(header, "FirstName:") == header)
strncpy(fname, header,127);
if (strstr(header, "LastName:") == header)
strncpy(lname, header,127);
if (strstr(header, "E-mail:") == header)
strncpy(netaddr, header,127);
if (strstr(header, "PicData:") == header)
strncpy(pixinfo, header,127);
if (strstr(header, "Image:") == header)
strncpy(imageinfo, header,127);
}
sscanf(pixinfo,"%s %d %d %d",scanline,&l,&k,&d);
if (l == 108 || l == 96)
k = 128;
else {
printf("Bad picture width %d\n", l);
exit (1);
}
d = 0;
/* Simpleminded stupid construction and output of a postscript */
/* program. This IS NOT proper encapsulated PostScript format */
sprintf(textout,"/piktur %d %d mul string def\n",k,l);
write(1,textout,strlen(textout));
sprintf(textout,"/main {\n/Helvetica findfont %d scalefont setfont\n",pt);
write(1,textout,strlen(textout));
sprintf(textout,"currentscreen /p exch def\n");
write(1,textout,strlen(textout));
sprintf(textout,"pop pop 50 45 /p load setscreen\n");
write(1,textout,strlen(textout));
/* This transfer function prevents pure white on 300 dpi laser printers */
sprintf(textout,
" { 1.05 mul 0.05 add dup .99 gt { pop .99 } if } settransfer\n");
write(1,textout,strlen(textout));
sprintf(textout,"gsave\n72 72 translate 108 %d moveto\n",d+pt+2);
write(1,textout,strlen(textout));
sprintf(textout,"(%s) show\n",fname);
write(1,textout,strlen(textout));
sprintf(textout,"108 %d moveto\n",d);
write(1,textout,strlen(textout));
sprintf(textout,"(%s) show\n",lname);
write(1,textout,strlen(textout));
sprintf(textout,"108 %d moveto\n",d-(pt+2));
write(1,textout,strlen(textout));
sprintf(textout,"(%s) show grestore\n",netaddr);
write(1,textout,strlen(textout));
/* This line causes the hex image to be read into the string 'piktur'*/
sprintf(textout,"currentfile piktur readhexstring pop pop \n");
write(1,textout,strlen(textout));
sprintf(textout,"72 -1100 translate\n0 0 moveto\n2.5 2.5 scale\n");
write(1,textout,strlen(textout));
/*The factor 1.125 compensates for rectangular pixels in the Targa Board*/
if (l == 108)
sprintf(textout, "360 1.125 div 1.375 mul 360 1.375 mul scale\n");
else
sprintf(textout, "360 1.375 mul 360 1.375 mul scale\n");
write(1,textout,strlen(textout));
/* These lines setup the matrix and display a large copy of the picture */
sprintf(textout,"%d %d 8 ",l,k);
write(1,textout,strlen(textout));
sprintf(textout,"[ 256 0 0 256 0 -256 ] \n");
write(1,textout,strlen(textout));
sprintf(textout,"{ piktur } image \n");
write(1,textout,strlen(textout));
sprintf(textout,"0.0 0.8 translate\n0.25 0.25 scale\n");
write(1,textout,strlen(textout));
/* These lines setup the matrix and display a small copy of the picture */
sprintf(textout,"%d %d 8 ",l,k);
write(1,textout,strlen(textout));
sprintf(textout,"[ 512 0 0 512 0 -256 ] \n");
write(1,textout,strlen(textout));
sprintf(textout," { piktur } ");
write(1,textout,strlen(textout));
sprintf(textout,"image showpage} def\n");
write(1,textout,strlen(textout));
sprintf(textout,"main\n");
write(1,textout,strlen(textout));
/* The Hexified file has the ouput scanlines broken into 4 pieces,
* and each piece is twice as wide as the number of pixels, since
* each byte is converted to two hex digits.
* Thus each piece is not too wide, for screen readability.
*/
m = l + 1; /* Hexified info plus newline */
for (i=0;i<k*4;i++) {
fgets(scanline,m,fp);
printf("%s",scanline);
}
/* Terminate the PostScript with an EOF */
printf("\n\004");
}